/*
 * EnigmaGM - A feature rich guild management system.
 * Copyright (C) 2007 ajiaojr.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */
package org.ajiaojr.enigmagm.client.service;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

import java.util.List;

/**
 * Service for accessing character information from the underlying storage.
 * 
 * @author ajiaojr
 */
public interface CharacterService extends RemoteService {
  /**
   * Utility class for simplifying access to the instance of async service.
   */
  public static class Util {
    private static CharacterServiceAsync instance;

    public static CharacterServiceAsync getInstance() {
      if (instance == null) {
        instance = (CharacterServiceAsync) GWT.create(CharacterService.class);
        ServiceDefTarget target = (ServiceDefTarget) instance;
        target.setServiceEntryPoint(GWT.getModuleBaseURL()
            + "/CharacterService");
      }
      return instance;
    }
  }

  /**
   * @param eventID
   * @param firstResult
   * @param maxResults
   * @return
   * @throws DataAccessException
   * @gwt.typeArgs <org.ajiaojr.enigmagm.client.data.Character>
   */
  public List findAttendees(int eventID, int firstResult, int maxResults)
      throws DataAccessException;

  /**
   * Finds the character according to the character's unique identifier.
   * 
   * @param characterID
   *          The unique identifier of the character.
   * @return
   * @throws DataAccessException
   */
  public org.ajiaojr.enigmagm.client.data.Character findByCharacterID(
      int characterID) throws DataAccessException;

  /**
   * @param username
   * @param firstResult
   * @param maxResults
   * @return
   * @throws DataAccessException
   * @gwt.typeArgs <org.ajiaojr.enigmagm.client.data.Character>
   */
  public List findByUser(String username, int firstResult, int maxResults)
      throws DataAccessException;

  /**
   * Lists all characters, sorts the characters according to the sort attribute
   * given.
   * 
   * @param sortAttribute
   *          attribute according to which characters are sorted.
   * @param ascending
   *          whether to sort the result in ascending order
   * @param firstResult
   *          index of the first result.
   * @param maxResults
   *          maximum number of results.
   * @return list of all characters.
   * @throws DataAccessException
   *           if error should occur during data access.
   * @gwt.typeArgs <org.ajiaojr.enigmagm.client.data.Character>
   */
  public List list(String sortAttribute, boolean ascending, int firstResult,
      int maxResults) throws DataAccessException;
}
